import Config from './config'
// import checkLogin from './egaiyi-verification-login'

class Pay {
	constructor() {}

	/**
	 * 下单
	 */
	pay(type, oid) {
		return new Promise(async (resolve, reject) => {
			try {
				if (type === 'wxPay') {
					const orderInfo = await this.wxPay(oid)
					// console.log(orderInfo);
					uni.hideLoading()
					await this.requestPayment({
						provider: 'wxpay',
						orderInfo: JSON.stringify(orderInfo)
						// orderInfo
					})
					resolve('支付成功！')
				} else if (type === 'aliPay') {
					const orderInfo = await this.aliPay(oid)
					uni.hideLoading()
					await this.requestPayment({
						provider: 'alipay',
						orderInfo
					})
					resolve('支付成功！')
				}
			} catch (err) {
				reject(err)
			}
		})
	}
	/**
	 * 获取支付宝支付参数
	 */
	aliPay(oid) {
		return new Promise((resolve, reject) => {
			
		})
	}
	/**
	 * 获取微信支付参数
	 */
	wxPay(orderId) {
		return new Promise((resolve, reject) => {
			
		})
	}

	/**
	 * 调用API跳转发起支付
	 */
	requestPayment(params) {
		console.log('common/js/pay', params);
		return new Promise((resolve, reject) => {
			uni.requestPayment({
				...params,
				success() {
					resolve('支付成功！')
				},
				fail(err) {
					uni.showToast({
						title: err,
						icon: 'none'
					})
					reject('支付失败！')
				},
				complete(res) {
					console.log(res);
				}
			})
		})
	}
}

export default new Pay()
